//
//  ABZoomSliderFloaterView.m
//  Flare
//
//  Created by Steven Troughton-Smith on 01/03/2008.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "ABZoomSliderFloaterView.h"


@implementation ABZoomSliderFloaterView

-(void)setSliderCell:(ABZoomSliderCell *)c
{

_sliderCell = c;

}

-(void)drawRect:(NSRect)r
{

NSBezierPath *path = [NSBezierPath bezierPath];

[path moveToPoint:NSMakePoint(r.size.width/2, 0)];
[path lineToPoint:NSMakePoint(20, 10)];
[path lineToPoint:NSMakePoint(r.size.width-20, 10)];
[path lineToPoint:NSMakePoint(r.size.width/2, 0)];
[path closePath];
[path appendBezierPathWithRoundedRect:NSMakeRect(0, 10,r.size.width,r.size.height-10) xRadius:4.0 yRadius:4.0];

NSGradient *grad = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedRed:255.0/255.0 green:255.0/255.0 blue:102.0/255.0 alpha:1.0] endingColor:[NSColor colorWithCalibratedRed:213.0/255.0 green:214.0/255.0 blue:69.0/255.0 alpha:1.0]];

[grad drawInBezierPath:path angle:-90];

CGFloat val = ([_sliderCell floatValue])*5;

NSRange decLoc = [[[NSNumber numberWithFloat:val] stringValue] rangeOfString:@"."];
NSString *value;

if (decLoc.length != 0)
value = [[[[NSNumber numberWithFloat:val] stringValue] substringToIndex:decLoc.location] stringByAppendingString:@"\%"];
else
value = [[[NSNumber numberWithFloat:val] stringValue] stringByAppendingString:@"\%"];

NSMutableDictionary *attributes = [[NSDictionary dictionaryWithObjectsAndKeys:
			[NSFont systemFontOfSize:13.0], NSFontAttributeName,
			[NSColor blackColor] , NSForegroundColorAttributeName,
			nil] mutableCopy];

		NSMutableParagraphStyle *pStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
		
		[pStyle setAlignment: NSCenterTextAlignment];
		[attributes setValue: pStyle forKey: NSParagraphStyleAttributeName];
		[pStyle release];
		[attributes autorelease];

[value drawInRect:NSMakeRect(5, 12, r.size.width-10,r.size.height-15) withAttributes:attributes];

}

@end

